<template>
  <div class="clue-container">
    <div class="header">
      <h2>线索管理</h2>
      <el-button type="primary" @click="handleAdd">新增线索</el-button>
    </div>

    <el-table :data="clueList" border style="width: 100%">
      <el-table-column prop="title" label="线索标题" width="200"/>
      <el-table-column prop="content" label="线索内容"/>
      <el-table-column prop="reportTime" label="上报时间" width="180"/>
      <el-table-column prop="status" label="处理状态" width="120"/>
      <el-table-column label="操作" width="200">
        <template #default="scope">
          <el-button size="small" @click="handleEdit(scope.row)">编辑</el-button>
          <el-button size="small" type="danger" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 新增/编辑对话框 -->
    <el-dialog
      :title="dialogTitle"
      v-model="dialogVisible"
      width="50%">
      <el-form :model="form" label-width="100px">
        <el-form-item label="线索标题">
          <el-input v-model="form.title"/>
        </el-form-item>
        <el-form-item label="线索内容">
          <el-input type="textarea" v-model="form.content" rows="4"/>
        </el-form-item>
        <el-form-item label="处理状态">
          <el-select v-model="form.status">
            <el-option label="待处理" value="待处理"/>
            <el-option label="处理中" value="处理中"/>
            <el-option label="已完成" value="已完成"/>
          </el-select>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="dialogVisible = false">取消</el-button>
          <el-button type="primary" @click="handleSubmit">确定</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script lang="ts" setup>
import { ref, reactive } from 'vue'

const clueList = ref([])
const dialogVisible = ref(false)
const dialogTitle = ref('新增线索')

const form = reactive({
  title: '',
  content: '',
  reportTime: '',
  status: '待处理'
})

const handleAdd = () => {
  dialogTitle.value = '新增线索'
  dialogVisible.value = true
}

const handleEdit = (row: any) => {
  dialogTitle.value = '编辑线索'
  Object.assign(form, row)
  dialogVisible.value = true
}

const handleDelete = (row: any) => {
  // TODO: 实现删除逻辑
}

const handleSubmit = () => {
  // TODO: 实现提交逻辑
  dialogVisible.value = false
}
</script>

<style scoped>
.clue-container {
  padding: 20px;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.header h2 {
  margin: 0;
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
</style>
